#!/bin/sh

PATH=/sbin:/bin:/usr/bin:/usr/sbin:%OPTWARE_TARGET_PREFIX%/bin:%OPTWARE_TARGET_PREFIX%/sbin

print_conf_info () {
	echo ; echo
	echo "A template configuration file is installed here : %OPTWARE_TARGET_PREFIX%/etc/eggdrop.conf"
	echo "Please read the eggdrop documentation to create a configuration file matching your needs."
	echo
}

if grep -q ^eggdrop: /etc/group; then
	echo There already is an eggdrop group on the system.
	ADDUSER_OPT="-G eggdrop"
fi

if grep -q ^eggdrop: /etc/passwd; then
	echo There already is an eggdrop user on the system.
else
	echo -n "No eggdrop user found, creating it... "
	adduser -S -h %OPTWARE_TARGET_PREFIX%/share/eggdrop -g "eggdrop daemon" -s /bin/false -D -H  $ADDUSER_OPT eggdrop > /dev/null 2>&1 || (echo "Warning! Failed to create eggdrop user/group"; print_conf_info; exit 0)
	echo done
fi
chown -R eggdrop.eggdrop %OPTWARE_TARGET_PREFIX%/share/eggdrop
chmod 700 %OPTWARE_TARGET_PREFIX%/share/eggdrop

print_conf_info
